<script>
import http from "@/utils/http.js";

export default {
  name: "index",
  data() {
    return {
      opType:1,
      codeImgUrl:'',
      buttonText:'',
      ruleFrom:{
        username: '',
        usernameVad: '',
        password: '',
        rePassword: '',
        email: '',
        checkEmail: '',
        emailCode: '',
        registerEmailCode: '',
        code: '',
        uuid: ''
      },
      rules: {
        username: [
          {required: true, message: '请输入用户名！！', trigger: 'blur'},
          {min: 7, max: 18, message: '用户名长度为7-11位', trigger: 'blur'},
          {pattern: /^[a-zA-Z][a-zA-Z0-9]{0,}$/, message: '需要由字母数字组成'}
        ],
        password: [
          {required: true, message: '请输入密码！！', trigger: 'blur'},
          {min: 8, max: 18, message: '长度长度为8-18位', trigger: 'blur'},
          {pattern: /^[a-zA-Z][a-zA-Z0-9]{0,}$/, message: '需要由字母数字组成'}
        ],
      },
      userDisabled:false,

    }
  },
  methods:{
    refreshCode(){
      http.get("/captcha/getCaptcha").then(res=>{
        this.codeImgUrl = 'data:image/png;base64,' + res.data.img
        this.ruleFrom.uuid = res.data.uuid
        console.log(res)
      })
    }
  },
  mounted() {
    this.refreshCode()
  }
}
</script>

<template>
  <div class="backgrounds">
    <div class="left">
      <div>
        The world's widest is the ocean, wider than the ocean is the sky, wider than the sky is the
        human mind. - "Les Miserables."
      </div>
    </div>
    <div class="right">
      <el-form
          class="login-boxs"
          ref="ruleFormRef"
          :model="ruleFrom"
          label-width="auto"
          :rules="rules"
      >
        <div class="loader_logo"></div>

        <div class="logo-head">
          <span>小卖部顶级系统</span>
        </div>

        <div class="content">
          <!-- 用户名 -->
          <el-form-item prop="username" v-if="opType === 1">
            <template #label>
              <span>用户名</span>
            </template>
            <el-input
                :disabled="userDisabled"
                placeholder="请输入账号（由字母数字组成）"
                v-model="ruleFrom.username"
            />
          </el-form-item>

          <!-- 登录密码 -->
          <el-form-item
              prop="password"
              v-if="opType === 0 || opType === 1 || opType === 2 || opType === 3"
          >
            <template #label>
              <span>密码</span>
            </template>
            <el-input placeholder="请输入密码" v-model="ruleFrom.password" show-password></el-input>
          </el-form-item>

          <!-- 验证码 -->
          <el-form-item prop="code" v-if="opType === 1">
            <template #label>
              <span>验证码</span>
            </template>
            <el-input v-model="ruleFrom.code" style="width: 60%"></el-input>
            <!-- 图片验证码 -->
            <el-image
                style="
                cursor: pointer;
                width: 39%;
                height: 90%;
                border-radius: 5px;
                /* margin-left: 10px; */
              "
                :src="codeImgUrl"
                fit="cover"
                @click="refreshCode"
            />
          </el-form-item>

          <!-- 登录按钮 -->
          <el-form-item class="button">
            <el-button v-if="opType === 1" type="primary" @click="submitForm()">
              <span>登录</span>
            </el-button>
          </el-form-item>

        </div>
        <!-- </div> -->
      </el-form>
    </div>
  </div>
</template>

<style lang="scss" scoped>
.backgrounds {
  height: 100vh;
  width: 100%;
  background-image: url(src/assets/15.webp);
  background-size: cover;
  display: flex;

  .left {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 55%;
    height: 100vh;

    div {
      font-size: 1.5em;
      margin: 50px;
      color: white;
      text-indent: 2em;
    }
  }

  .right {
    width: 45%;
    display: flex;
    justify-content: center;
    align-items: center;
    background: rgb(0 0 0 / 6%);
    backdrop-filter: blur(14px);
    -webkit-backdrop-filter: blur(14px);

    .login-boxs {
      margin: 0 10px;

      .logo-head {
        display: flex;
        justify-content: center;
        align-items: center;
        font-size: 30px;
        color: white;
        font-weight: 900;
        text-shadow: 0 0 2px black;
        filter: drop-shadow(0 0 5px rgb(255, 255, 255));
      }

      .content {
        .el-form-item {
          // font-size: larger;
          height: 5vh;

          span {
            color: white;
          }
        }

        .toggle-button {
          display: flex;
          width: 100%;
          justify-content: space-around;
          color: rgb(255, 255, 255);
          margin: 20px 0;

          span {
            cursor: pointer;
          }

          span:hover {
            text-shadow: 0 0px 3px rgb(0, 0, 0);
          }
        }

        .button {
          .el-button {
            width: 100%;
          }
        }
      }
    }
  }
}

@media (max-width: 570px) {
  .backgrounds {
    .left {
      display: none;
    }

    .right {
      width: 100%;
    }
  }
}
</style>